package com.itheima.exception;

public class Test2 {

    public static void main(String[] args) {

        //1.自定义编译时异常
        System.out.println("程序开始");
        try {
            checkAge(-10);
            System.out.println("底层方法执行成功");
        } catch (AgeIllegalException e) {
            e.printStackTrace();
            System.out.println("底层方法执行失败");
        }
        System.out.println("程序结束");


    }

    //定义年龄不合法异常
    public static void checkAge(int age) throws AgeIllegalException{

        if(age < 0 || age > 120){
            throw new AgeIllegalException("年龄不合法，年龄必须大于0小于120");
        }else {
            System.out.println("年龄合法");
        }
    }
}
